package flc.ast.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.os.Bundle;
import android.view.View;

import java.util.ArrayList;
import java.util.List;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.adapter.ResultAdapter;
import flc.ast.bean.ResultBean;
import flc.ast.databinding.ActivityResultBinding;
import stark.common.basic.event.EventStatProxy;

public class ResultActivity extends BaseAc<ActivityResultBinding> {

    public static List<ResultBean> listResult = new ArrayList<>();
    private ResultAdapter resultAdapter;

    @Override
    protected int onCreate() {
        return R.layout.activity_result;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(this, mDataBinding.event1Container);

        mDataBinding.ivResultBack.setOnClickListener(v -> onBackPressed());

        mDataBinding.ivResultAgain.setOnClickListener(this);

        mDataBinding.rvResultList.setLayoutManager(new LinearLayoutManager(mContext));
        resultAdapter = new ResultAdapter();
        mDataBinding.rvResultList.setAdapter(resultAdapter);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.ivResultAgain://再玩一局
                startActivity(GuessActivity.class);
                finish();
                break;
        }
    }

    @Override
    protected void initData() {
        if (listResult.size() > 0) {
            int num = 0;
            for (ResultBean resultBean : listResult) {
                if (resultBean.isRight()) {
                    num++;
                }
            }
            resultAdapter.setList(listResult);
            mDataBinding.rvResultList.setVisibility(View.VISIBLE);
            mDataBinding.tvResultNum.setText(num + "");
        } else {
            mDataBinding.rvResultList.setVisibility(View.GONE);
            mDataBinding.tvResultNum.setText(listResult.size() + "");
        }
    }
}